package com.curricula.curriculum.vo;

import java.io.Serializable;
import java.lang.reflect.Method;

import org.apache.log4j.Logger;

/**
 * @author Cesar Cabrera
 */
public class VO implements Serializable{
	
	private static final long serialVersionUID = 1L;
	
	public boolean equals(Object obj) {
		boolean response = false;
		
		if (obj instanceof VO)
			response = this.toString().trim().equals(obj.toString().trim());
		
		return response;
	}
	
	@SuppressWarnings("unchecked")
	public String toString(){
		
		StringBuffer response = new StringBuffer("");
		
		try{
			Class clase 	 = this.getClass();
			Method[] metodos = clase.getDeclaredMethods();			
			response.append(this.getClass().getName().substring(this.getClass().getName().lastIndexOf(".") + 1) + " { " );			
			for(int i = 0; i<metodos.length; i++){
				if( metodos[i].getParameterTypes().length == 0 ){
					response.append(metodos[i].getName()+": ");
					response.append(metodos[i].invoke(this,(Object)null) + ", ");
				}//end if
			}//end for
			response.replace(response.lastIndexOf(", "), response.length(), " }");
			
		}catch(Exception ignored){
			ignored.printStackTrace();
			Logger.getLogger(this.getClass()).info(ignored);
		}
		
		return response.toString();
	}

}
